// pages/doNotMiss/doNotMiss.js
const util = require('../../utils/util.js')
const auth = require('../../utils/auth.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingData:false,
    pageId:'',
    image: '',
    title: '',
    time: '',
    detail: '',
    main:'',
    loading:false,
    collectionStatus:true,
    couponImg:{
      couponTrue:'../../img/holiday-true.png',
      couponFalse:'../../img/holiday-false.png'
    },
    mark1:'http://p.qpic.cn/automall_pic/0/20180223145200_85318/0',
    mark2:'http://p.qpic.cn/automall_pic/0/20180223145339_81630/0'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this ;
      var id = options.id;
      that.setData({
         pageId:id
      });
      util.ajax({
        url:'act/actapi/detail',
        data: {
          id:that.data.pageId
      },
      header: {
          'content-type': 'application/json' // 默认值
      },
      success: function(res) {
         if(res.data){
        console.log(res.data);
        //var sourse = res.data.list
        var collStatus = res.data.is_collect
        console.log(res);
        var res = res.data;
        var img = res.head_url;
        var main = res.content;
        var detail = res.brief;
        var title = res.title;
        var time = res.publish_time;
        var timeTemp = time.split(' ');
        var tempContent = new Array();
        for(var i=0;i<main.length;i++){
          tempContent[i] = new Array();
          tempContent[i].push(main[i].content.split("<&p&>"));
          main[i].content = tempContent[i];
        }
        that.setData({
           main:main,
           detail:detail,
           title:title,
           time:timeTemp[0],
           image:img,
           loading:true
        });
         if(collStatus){
            that.setData({
              collectionStatus:false
            });
         }else{
            that.setData({
               collectionStatus:true
            }); 
         }
         that.setData({
            loadingData:true
         })
       } 
        
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
 previewImage: function(e) {
    if(this.data.pageId ==30){
       wx.previewImage({  
         urls: this.data.mark1.split(',')
      }) 
    }else{
       wx.previewImage({  
         urls: this.data.mark2.split(',')
      }) 
    }
   
 },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  turn: function (e) {
    wx.showToast({
      title: '已收藏',
      duration: 1000
    })
    this.setData({
      collectionStatus:false
    })
    var that=this;
     util.ajax({
      url: 'act/actapi/collect',
      data: {
          id:that.data.pageId,
          collect:1
      },
      header: {
          'content-type': 'application/json' // 默认值
      },
      success: function(res) {
          
       
      }
    })
  },
  back :function (e){
    wx.showToast({
      title: '已取消收藏',
      duration: 1000
    })
    this.setData({
      collectionStatus: true
    })
    var that=this;
     util.ajax({
      url: 'act/actapi/collect',
      data: {
          id:that.data.pageId,
          collect:2
      },
      header: {
          'content-type': 'application/json' // 默认值
      },
      success: function(res) {

      }
    })
  },
})